package bean;

import static com.sun.corba.se.spi.presentation.rmi.StubAdapter.request;
import dao.CarrinhoDAO;
import model.entity.Carrinho;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 *
 * @author CesarFrantz
 */
@ManagedBean
@RequestScoped
public class CarrinhoBean {

    private CarrinhoDAO carrinhoDAO = new CarrinhoDAO();
    private Carrinho carrinho = new Carrinho();

    public CarrinhoDAO getCarrinhoDAO() {
        return carrinhoDAO;
    }

    public void setCarrinhoDAO(CarrinhoDAO carrinhoDAO) {
        this.carrinhoDAO = carrinhoDAO;
    }

    public Carrinho getCarrinho() {
        return carrinho;
    }

    public void setCarrinho(Carrinho carrinho) {
        this.carrinho = carrinho;
    }

    public String removerJogoCarrinho(int idjogo) {
        Integer idusuario = (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("user_id") != null) ? (Integer) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("user_id") : '1';

        carrinhoDAO.removeJogoCarrinho(idjogo);
        return "carrinho.xhtml";
    }

    public String addJogoCarrinho(int idjogo) {
        carrinhoDAO.addJogoCarrinho(idjogo);
        return "carrinho.xhtml";
    }
}
